home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
asmutil
/
uasm.zip
/
UASM.C
< prev
next >
Wrap
C/C++ Source or Header
|
1986-04-06
|
22KB
|
873 lines
/*
UASM - UNIVERSAL CROSS ASSMEBLER uasm.c
CUSTOM COMPUTER CONSULTANTS
5 April 1986
*/
#include <stdio.h>
#include <uasm.h>
#define NHASH 512
#define HP1 7
#define HP2 2
/* Flags */
int sf, lf, hf, nolist ;
int pass1, pass2 ;
int lbl ;
int info ;
int valid ;
/* Numbers */
int i, j, k ;
int kk, r ;
int lineno, lnspp, pgno ;
int cc ; /* character count */
int mcc ; /* mark character count */
int ll ; /* line length */
int maxop ;
int maxpseudo ;
int ilc, active ;
int il[NSEG] ;
int instl ;
int parval ;
int num ;
int radix ;
int cput ; /* ib pointer */
int errcnt, esp ;
int syte, sytx ;
unsigned unpar ;
unsigned ht ; /* Record Type */
unsigned ha ; /* Record Start Address */
unsigned he ; /* Expected Address of next item */
unsigned hc ; /* Checksum Mod 256 */
unsigned hsp ; /* Hex String Pointer */
long start, finish, time() ;
#define NOW (0L)
/* Characters */
unsigned char ch ; /* last character */
unsigned char nch ; /* next character */
unsigned char sym ; /* last symbol */
/* Pointers */
char *iptr ; /* Input Buffer */
char *src ; /* Source File Name */
char *cp ; /* General Purpose */
/* Character Arrays */
char hex[13] ; /* Hex File Name */
char lst[13] ; /* List File Name */
char segtype[NSEG] ;
char id[AL] ; /* Last Identifier */
unsigned char ib[256] ; /* Instruction Byte Queue */
unsigned char ssym[256] ; /* character symbols */
unsigned char hs[MAXB] ;
char errstk[25] ;
unsigned char pv[200] ;
unsigned char px[80] ;
int pj[15] ;
int qhash[NHASH] ; /* Head indexes for hash chains */
int nlook, nprobe ;
int maxprobe ;
/* Pointer Arrays */
char *pc[80], *pseudo[15] ;
int (*pp[200])() ;
int (*ppo[15])() ;
/* I/O Buffers */
char ibuf[MAXLINE] ;
FILE *dibuf, *libuf, *hxbuf ;
struct symbol symtab[NSYM] ;
int psym[NSYM] ;
extern char push() ;
extern char pop() ;
extern int cpmf() ;
extern char *strcat() ;
extern char *version ;
/*
Control Programs
main() Open files, assemble, close files, exit
assemble() Process input and create tables
code() Generate object output
list() Generate Listing
*/
main(narg,argv)
int narg;
char **argv;
{
start = time(NOW) ;
puts("\033[2J") ; /* CLEAR_SCREEN */
puts("Universal Cross Assembler -- V1.4 4/5/86\n") ;
puts("(c) Custom Computer Consultants, 1986\n") ;
puts(version) ;
sf = lf = hf = nolist = FALSE ;
/* FILE OPERATIONS */
if( --narg > 0 ) {
dibuf = fopen( *(++argv), "r" ) ;
if( dibuf == NULL ) abort("Source ?\n") ;
src = *argv ; sf = TRUE ;
}
if( --narg > 0 ) {
j = 0 ;
while( **argv != '.' && j < 8 ) {
hex[j] = lst[j] = *(*argv)++ ;
++j ;
}
hex[j] = lst[j] = EOS ;
strcat( hex, ".HEX" ) ;
strcat( lst, ".LST" ) ;
++argv ;
while( ch = *(*argv)++ ) {
if((ch == 'L') || (ch == 'l')) {
libuf = fopen(lst,"w") ;
if( libuf == NULL ) abort("List ?\n") ;
lf = TRUE ;
}
else if((ch == 'O') || (ch == 'o')) {
hxbuf = fopen(hex,"w") ;
if( hxbuf == NULL ) abort("Hex ?\n") ;
hf = TRUE ;
}
else if((ch == 'N') || (ch == 'n')) nolist = TRUE ;
} /* END while(ch = *(*argv)++ ) */
} /* END if(--narg > 0) */
syte = pgno = lnspp = 0 ;
nlook = nprobe = maxprobe = 0 ;
setmem(ssym,256,NUL) ; /* NUL is the token value \200 */
setmem(qhash,2*NHASH,ERROR) ;
cp = "$+-*/(),;%~|&^'@#.<>\"" ;
while( ch = *cp++ ) ssym[ch]=ch ;
set_type() ;
maxpseudo = build_pseudo() ;
maxop = buildopc();
pass1 = sf ? TRUE : FALSE ;
pass2 = sf ? FALSE : TRUE ;
/* Main Assembler Loop */
while ( pass1 || pass2 ) {
if ( pass1 ) puts("Pass 1 : ") ;
if ( pass2 ) puts("Pass 2 : ") ;
lineno = 1;
set_il() ;
active = code_seg() ;
hsp = hc = ht = 0 ;
ha = he = ilc = il[active] ;
errcnt = 0 ;
radix = 10 ;
while(( getline(ibuf)) != EOF ) {
info = assemble() ;
code() ;
list() ;
lineno++ ;
ilc += instl ;
} /* end while on getline(ibuf) */
if ( sf ) {
fclose(dibuf) ;
dibuf = pass1 ? fopen(src,"r") : dibuf ;
if( dibuf == NULL ) abort("Source Reopen ?\n") ;
}
pass1 = FALSE ;
pass2 = pass2 ? FALSE : TRUE ;
finish = time(NOW) ;
printf("\t%5ld\tseconds\n",finish-start) ;
} /* end while on pass1 || pass2 */
/* Sort the Symbol Table */
if ( syte ) {
qsort(psym,syte,sizeof(int),cpmf) ;
}
/* Print the Symbol Table */
if( !nolist ) {
cprintf("\fSymbol Table\n\n") ;
for ( i = 0 ; i < syte ; i++ ) {
if ( i % 5 == 0 ) cprintf("\n") ;
sytx = psym[i] ;
cprintf("%-12s%04x%c ",symtab[sytx].name,
symtab[sytx].value,
segtype[symtab[sytx].flags & (NSEG-1)] ) ;
}
}
cprintf("\n\n") ;
if( errcnt > 0 ) {
cprintf("%04d ERRORS\n",errcnt) ;
if( nolist || lf ) printf("\n%04d ERRORS\n",errcnt) ;
}
else {
cprintf(" NO ERRORS\n") ;
if( nolist || lf ) puts("\n NO ERRORS\n") ;
}
if ( lf ) {
putc(CPMEOF,libuf) ;
fflush(libuf) ;
fclose(libuf) ;
}
if ( hf ) {
hsout() ;
fprintf(hxbuf,":00000001FF\n") ;
putc(CPMEOF,hxbuf) ;
fflush(hxbuf) ;
fclose(hxbuf) ;
}
puts("ASSEMBLY COMPLETE\n");
finish = time(NOW) ;
printf("\n%5ld\tseconds\n",finish-start) ;
printf("%5ld\tlines/minute\n",lineno*60/(finish-start)) ;
printf("%5d\tprobes\n%5d\tlookups\n",nprobe,nlook) ;
printf("%5.2f\tprobes/lookup\n",(float)nprobe/(float)nlook) ;
printf("%5d\tmaximum probe\n",maxprobe) ;
nprobe = 0 ;
for (nlook = 0 ; nlook < NHASH ; ++nlook ) {
if( qhash[nlook] != ERROR ) ++nprobe ;
}
printf("%5d\thash entries\n",nprobe) ;
printf("%5d\tpercent utilization\n",(100*nprobe)/nlook) ;
exit();
}
cpmf(a,b)
int *a, *b ;
{
return strcmp(symtab[*a].name,symtab[*b].name) ;
}
#define INFO 1
#define NOINFO 0
assemble()
{
setmem(ib,4,0) ; /*